import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Gegner here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public abstract class Gegner extends Actor
{
    int level;
    int hp;
    int dmg;
    int speed; // Maximalgeschwindigkeit
    Trip trip;
    Trap trap;
    boolean first;
    GreenfootSound angriff = new GreenfootSound("angriff.wav");
    GreenfootSound vernichten = new GreenfootSound("vernichten.wav");

    public Gegner(int l)
    {
        level = l;
        first = true;
    }

    /**
     * Act - do whatever the Gegner wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if(first)
        {
            trip = ((Welt)getWorld()).getTrip();
            trap = ((Welt)getWorld()).getTrap();
            first = false;
        }
        if(Greenfoot.getRandomNumber(100)<1) angriff.play();
    }    

    public void schießen(boolean x, int s, int d, String pfad)
    {
        if(Greenfoot.getRandomNumber(10)<1) vernichten.play();
        int r = 1;
        if(Greenfoot.getRandomNumber(2)<1) 
        {
            if(trip.getX() < getX()) r = -1;
        }
        else 
        {
            if(trap.getX() < getX()) r = -1;
        }
        Projektil p = new Projektil(x, r, s, d, pfad);
        getWorld().addObject(p, getX(), getY());
    }

    public void hit(int dmg)
    {
        hp = hp - dmg;
        sterben();
    }

    public void sterben()
    {
        if(hp<=0) getWorld().removeObject(this);
    }

}
